/**
 *
 * @author 
 *
 */
class Page3 extends egret.Sprite{
    private _main: Main;
    public constructor(main: Main) {
        super();
        this._main = main;
        
       
        //this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.thisClick,this);
        
    }
    
    private touchMove(e: egret.TouchEvent): void {
        this.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.thisClickMove,this);
    }
    
    private mClickNum: number = 0;
    private mSkin: Boolean;
    private m_move_y = 0;
    private mChangeing: boolean;

    private thisClickMove(e: egret.TouchEvent): void {
        if(this.mChangeing) return;
        if(this.m_move_y == 0)
            this.m_move_y = e.stageY;
        else
            if(this.m_move_y > e.stageY)
            {
                this.mChangeing = true;
                this._main.toPage4(this, true);
                egret.setTimeout(clean, this, 500);

            }
            else if(this.m_move_y == e.stageY)
            {}
            else
            {
                this.mChangeing = true;
                this._main.toPage2(this, false);
                egret.setTimeout(clean, this, 500);

            }
            
        function clean(): void
        {
            this.mChangeing = false;
        }
    }
    
    private thisClick(e: egret.TouchEvent): void
    {
        this.mClickNum++;
        if(this.mClickNum == 1)
        {
            this.mSkin = true;
            return;
        }

        if(this.mClickNum >= 2)
        {
            this._main.toPage4(this, true);
            return;
        }
    }

    public start(): void {
        egret.setTimeout(this.touchMove,this,this.mSkin ? 0 : 500);
        
        var bg: eui.Image = new eui.Image;
        bg.source = "1_1_png";
        this.addChild(bg);
        
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_arrows_png";
        bg2.x = 300;
        bg2.y = 960;
        this.addChild(bg2);
        
        egret.setTimeout(this.page1, this, this.mSkin ? 0 :100);
    }
    
    public page1(): void {
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_3_1_png";
        bg2.x = -370;
        bg2.y = 30;
        bg2.alpha = 0;
        this.addChild(bg2);
            
        egret.Tween.get(bg2).to({
            x: 0,alpha:1,ease: egret.Ease.bounceOut
        }, this.mSkin ? 0 :500)
        
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_3_2_png";
        bg2.x = 470;
        bg2.y = 230;
        bg2.alpha = 0;
        this.addChild(bg2);

        egret.Tween.get(bg2).to({
            x: 340,alpha: 1,ease: egret.Ease.bounceOut
        },this.mSkin ? 0 : 500)
        
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_3_5_png";
        bg2.x = 80;
        bg2.y = 900;
        bg2.alpha = 0;
        this.addChild(bg2);

        egret.Tween.get(bg2).to({
            y: 740,alpha:1,ease: egret.Ease.bounceOut
        },this.mSkin ? 0 : 500)
        
        egret.setTimeout(this.page2, this, this.mSkin ? 0 : this.mSkin ? 0 : 200);
    }

    public page2(): void {
        
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_3_6_png";
        bg2.x = 55;
        bg2.y = 435;
        bg2.alpha = 0;
        this.addChild(bg2);

        egret.Tween.get(bg2).to({
            alpha: 1
        },this.mSkin ? 0 : 500)
        
        egret.setTimeout(this.page3, this, this.mSkin ? 0 : this.mSkin ? 0 :200);
    }
    
    public page3(): void {
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_3_3_png";
        bg2.x = 470;
        bg2.y = 380;
        bg2.alpha = 0;
        this.addChild(bg2);

        egret.Tween.get(bg2).to({
            x: 270,alpha:1,ease: egret.Ease.bounceOut
        },this.mSkin ? 0 : 500)

        egret.setTimeout(this.page4, this, this.mSkin ? 0 : this.mSkin ? 0 :200);
    }
    
    public page4(): void {
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_3_4_png";
        bg2.x = 380;
        bg2.y = 620;
        bg2.alpha = 0;
        this.addChild(bg2);

        egret.Tween.get(bg2).to({
            alpha : 1
        },this.mSkin ? 0 : 500)

        this.mClickNum = 1
    }
}
